package com.zs.zcerp.entrance.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zs.zcerp.entrance.entity.EpPhoto;
import com.zs.zcerp.entrance.entity.Syorg;
import com.zs.zcerp.entrance.mapper.EpPhotoMapper;
import com.zs.zcerp.entrance.mapper.SyorgMapper;
import com.zs.zcerp.entrance.service.IEpPhotoService;
import com.zs.zcerp.entrance.service.ISyorgService;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.List;

@DS("oracle2")
@Service
public class EpPhotoServiceImpl extends ServiceImpl<EpPhotoMapper, EpPhoto> implements IEpPhotoService {

    @Override
    public EpPhoto findByEmpNo(String empNo) {
        return baseMapper.selectOne(new QueryWrapper<EpPhoto>().eq("EMP_NO", empNo));
    }

    @Override
    public Integer savePhoto(EpPhoto epPhoto) {
        return baseMapper.insert(epPhoto);
    }

    @Override
    public Integer updatePhoto(EpPhoto epPhoto) {
        return baseMapper.update(epPhoto, new QueryWrapper<EpPhoto>().eq("EMP_NO", epPhoto.getEmpNo()));
    }

    @Override
    public Integer saveOrUpdatePhoto(EpPhoto epPhoto) {
        int i = 0;
        try {
            i = savePhoto(epPhoto);
        } catch (Exception e) {
            i = updatePhoto(epPhoto);
            e.printStackTrace();
        }
        return i;
    }
}
